package cn.itcast.test;

import org.apache.logging.log4j.core.util.Assert;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 15:55 2019/3/18
 * @Version 1.0
 **/
public class testdate {
    public static String timeZoneTransfer(String time, String pattern, String nowTimeZone, String targetTimeZone) {
        if (StringUtils.isBlank(time)) {
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT" + nowTimeZone));
        Date date;
        try {
            date = simpleDateFormat.parse(time);
        } catch (ParseException e) {
            return "";
        }
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT" + targetTimeZone));
        return simpleDateFormat.format(date);
    }

    @Test
    public void testTimeZoneTransfer() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        Date date = new Date(1553098811845L);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'");
        String format = df.format(date);
        System.out.println(format);
    }

    @Test
    public void Oo() {
        int[] score = {1, 2, 23, 89, 12};
        //遍历 N-1次
        for (int i = 0; i < score.length - 1; i++) {
            //内层遍历比较大小
            for (int j = 0; j < score.length - i - 1; j++) {
                //如果前一个大于后一个
                if (score[j] < score[j + 1]) {
                    int tem = score[j + 1];
                    //前面的放到后面去
                    score[j + 1] = score[j];
                    score[j] = tem;
                }
            }
        }
        for (int i : score) {
            System.out.println(i);
        }

        //逆序
        for (int i = 0; i < score.length - 1; i++) {
            //内层遍历比较大小
            for (int j = 0; j < score.length - i - 1; j++) {
                //如果前一个大于后一个
                if (score[j] < score[j + 1]) {
                    int tem = score[j];
                    //前面的放到后面去
                    score[j] = score[j + 1];
                    score[j + 1] = tem;
                }
            }
        }
        for (int i : score) {
            System.out.println(i);
        }


    }

    @Test
    public void singleNumber() {
        int[] nums = {2,3,3,33,33,4,2,1,1};
        int num = 0;
        for (int i = 0; i < nums.length; i++) {
            System.out.println(num ^ nums[i]);
            num = num ^ nums[i];
        }
        System.out.println(num);
        // System.out.println(0 ^ 122);

    }
}
